class Solution
{
public:
    vector<int> powerfulIntegers(int x, int y, int bound)
    {
        unordered_set<int> result;
        int xi = 1;
        int yi = 1;
        while (xi < bound)
        {
            while (xi + yi <= bound)
            {
                result.insert(xi + yi);
                if (y == 1)
                {
                    break;
                }
                yi *= y;
            }
            if (x == 1)
            {
                break;
            }
            xi *= x;
            yi = 1;
        }
        return {result.begin(), result.end()};
    }
};